﻿using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

namespace SpectrumAnalyser.ServiceClientProxy

{
    public class CustomClientBase<TChannel> : DebugClientBase<TChannel> where TChannel : class
    {
        public CustomClientBase(IEnumerable<IEndpointBehavior> endpointBehaviors, Binding binding, EndpointAddress endpointAddress) : base(binding, endpointAddress)
        {
            foreach (var endpointBehavior in endpointBehaviors)
            {
                this.Endpoint.Behaviors.Add(endpointBehavior);
            }

            foreach (OperationDescription op in this.Endpoint.Contract.Operations)
            {
                DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                if (dataContractBehavior != null)
                {
                    dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                }
            }
        }
    }
}